<!DOCTYPE html>
<html>
    <head>
        <title>图书借阅小程序后台管理系统</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <!-- Bootstrap -->
        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
        <link href="assets/styles.css" rel="stylesheet" media="screen">
        <link href="assets/DT_bootstrap.css" rel="stylesheet" media="screen">
        <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="vendors/flot/excanvas.min.js"></script><![endif]-->
        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
            <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <script src="vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
    </head>

    <body>
    <div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">录入书籍</h4>
                </div>
                <div class="modal-body">
                    <form role="form" id="addform" onsubmit="return false" action="#" method="post">
                        <div class="form-group">
                            <label for="name">封面</label>
                            <input id="cert" type="file" class="form-control"/>
                        </div>
                        <div class="form-group">
                            <label for="name">名称</label>
                            <input type="text" class="form-control" name="name" id="name" style="width: 90%" placeholder="请输入名称" required="required">
                        </div>
                        <div class="form-group">
                            <label for="name">作者</label>
                            <input type="text" class="form-control" name="ct" id="ct" style="width: 90%" placeholder="请输入作者" required="required">
                        </div>
                        <div class="form-group">
                            <label for="name">介绍</label>
                            <textarea class="form-control" name="intro" id="intro" placeholder="请输入介绍" style="width: 90%" required="required">
                            </textarea>
                        </div>
                        <div style="text-align: center">
                            <button type="submit" id="addb" class="btn btn-success">新增</button>
                        </div>
                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
       <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                    </a>
                    <a class="brand" href="index.html">图书借阅小程序后台管理系统</a>
                    <div class="nav-collapse collapse">
                        <ul class="nav pull-right">
                            <li class="dropdown">
                                <a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="icon-user"></i><span class="adminname"></span>  <i class="caret"></i>

                                </a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a tabindex="-1" href="changepassword.html">修改密码</a>
                                    </li>
                                    <li class="divider"></li>
                                    <li>
                                        <a tabindex="-1" onclick="logout()" href="#">注销</a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                    <!--/.nav-collapse -->
                </div>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span3" id="sidebar">
                    <ul class="nav nav-list bs-docs-sidenav nav-collapse collapse">
                        <li>
                            <a href="index.html"><i class="icon-chevron-right"></i> 主面板</a>
                        </li>
                        <li class="active">
                            <a href="book.html"><i class="icon-chevron-right"></i> 图书管理</a>
                        </li>
                        <li>
                            <a href="lent.html"><i class="icon-chevron-right"></i> 借阅管理</a>
                        </li>
                        <li>
                            <a href="student.html"><i class="icon-chevron-right"></i> 读者管理</a>
                        </li>
                        <li>
                            <a href="notice.html"><i class="icon-chevron-right"></i> 公告管理</a>
                        </li>
                    </ul>
                </div>

                <!--/span-->
                <div class="span9" id="content">
                    <div class="row-fluid">
                        <div class="alert alert-success">
                            <button type="button" class="close" data-dismiss="alert">&times;</button>
                            <h4>欢迎您</h4>
                            本页面可进行数据导入和导出，可进行数据查看，修改，删除，查询</div>
                            <div class="navbar">
                                <div class="navbar-inner">
                                    <ul class="breadcrumb">
                                        <li>
                                            <a href="index.html">主面板</a> <span class="divider">/</span>
                                        </li>
                                        <li class="active">图书管理</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    <div class="row-fluid">
                        <div class="span12">
                            <!-- block -->
                            <div class="block">
                                <div class="navbar navbar-inner block-header">
                                    <div class="muted pull-left">功能区</div>
                                </div>
                                <div class="block-content collapse in">
                                        <input type="text" placeholder="输入书名搜索" oninput="OnInput(this)" onpropertychange="OnPropChanged(this)" class="form-control" id="name">
                                        <input type="text" placeholder="输入书号搜索" oninput="OnInput(this)" onpropertychange="OnPropChanged(this)" class="form-control" id="id">
                                        <br>
                                        <div class="btn-group">
                                            <button class="btn btn-warning" data-toggle="modal" data-target="#add">新增图书</button>
                                            <a class="btn btn-success" href="base/excel?db=book">导出图书数据</a>
                                        </div><!-- /btn-group -->
                                </div>
                            </div>
                            <!-- /block -->
                        </div>
                    </div>
                    <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">图书管理</div>
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
  									<table class="table">
						              <thead>
						                <tr>
						                  <th>唯一标志</th>
						                  <th>书名</th>
						                  <th>作者</th>
                                          <th>更新日期</th>
                                          <th>图书状态</th>
						                  <th>操作</th>
						                </tr>
						              </thead>
						              <tbody id="info">
						              </tbody>
						            </table>
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>
                </div>
            </div>
            <hr>
            <footer>
<!--                <p>&copy; 2024 - 毕业快乐</p>-->
            </footer>
        </div>
        <!--/.fluid-container-->

        <script src="vendors/jquery-1.9.1.js"></script>
        <script src="bootstrap/js/bootstrap.min.js"></script>
        <script src="vendors/datatables/js/jquery.dataTables.min.js"></script>


        <script src="assets/scripts.js"></script>
       <script src="assets/DT_bootstrap.js"></script>
       <script src="base.js"></script>
       <script src="info.js"></script>
       <script>
           var type = "book";
           $(function() {
               var user = iflogin();
               $(".adminname").html(user.aname);

               var info = getall(type);
               pl(info);

           });
           $("#addb").click(function () {
                submit();
           });

           function submit(){
               var type = "file";          //后台接收时需要的参数名称，自定义即可
               var id = "cert";            //即input的id，用来寻找值
               var formData = new FormData();
               formData.append(type, $("#"+id)[0].files[0]);    //生成一对表单属性
               formData.append("name", $("#name").val());
               formData.append("ct", $("#ct").val());
               formData.append("intro", $("#intro").val());
               $.ajax({
                   type: "POST",           //因为是传输文件，所以必须是post
                   url: 'book/add',         //对应的后台处理类的地址
                   data: formData,
                   processData: false,
                   contentType: false,
                   success: function (data) {
                       alert(data.obj);
                       if(data.status==1){
                           window.location.reload();
                       }
                   }
               });
           }
           function delf(id) {
               del(type,id);
           }
           // Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 9
           function OnInput (event) {
               pl(search(type,event.id,event.value));
           }
           // Internet Explorer
           function OnPropChanged (event) {
               pl(search(type,event.id,event.value));
           }
           function pl(info) {
               $("#info").html("");
               for (let i = 0; i < info.length; i++) {
                   var v = info[i];
                   $("#info").append(
                       '<tr>' +
                       '<td>'+v.id+'</td>' +
                       '<td>'+v.name+'</td>' +
                       '<td>'+v.ct+'</td>' +
                       '<td>'+v.ut+'</td>' +
                       '<td>'+v.status+'</td>' +
                       '<td><a href="'+type+'info.html?id='+v.id+'" class="btn btn-success">详情</a><a onclick="delf('+v.id+')" class="btn btn-danger">删除</a></td>' +
                       '</tr>'
                   )
               }
           }
       </script>
    </body>

</html>
